package divinity.utils.web.loaders
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	
	public class AssetLoader extends Loader
	{
		private var _loaded:Boolean=false; 
		private var _dest:*;
		private var _target:*;
		public function AssetLoader()
		{
			super();
		}
		private function assetLoaded(e:Event)
		{					
			_loaded=true;			
			_dest[_target]=content;				
			dispatchEvent(new Event(Event.COMPLETE))
			contentLoaderInfo.removeEventListener(Event.COMPLETE,assetLoaded);	
			contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,progress);	
		}
		private function progress(e:ProgressEvent)
		{			
			dispatchEvent(e);
		}
		/**
		 * 
		 * Sets what file is to be loaded into what reference
		 * @param url  url of the file
		 * @param dest destination reference
		 * @param targ reference target
		 * 
		 * */
		public function loadFile(url:String,dest:Object,targ:String)
		{		
			_dest=dest;
			_target=targ;
			var req:URLRequest=new URLRequest(url);			
			contentLoaderInfo.addEventListener(Event.COMPLETE,assetLoaded);
			contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progress);	
			load(req);
		}
		
		/**
		 * 
		 * 
		 * GETTERS/SETTERS
		 * 
		 * 
		 * */
		public function get loaded():Boolean
		{
			return _loaded;
		}

		public function set loaded(value:Boolean):void
		{
			_loaded = value;
		}
		public function get fileTotal():Number
		{
			return contentLoaderInfo.bytesTotal;
		}
		public function get fileLoaded():Number
		{
			return contentLoaderInfo.bytesTotal;
		}

		
	}
}